<?php
require_once("yammerView.php");
require_once(CORE_DIR.'yammerModel.php');

class getStatusAction extends authAction{

	function __construct(){
		$this->view = new yammerView();
	}

	public function run($get, $post, $viewtype) {
		parent::run($get,$post,$viewtype);
		
		$yModel = new yammerModel();	
		
		$status = false;
		$errMessage = "";
		$yammerRequestToken = "";
		
		if (isset($get["userid"])) {
			$userid = $get["userid"];
			$status = $yModel->isYammerActive($userid);
			
			if (!$status)
			{
				$tokens = $yModel->getRequestTokens();
				
				$oauth_token = $tokens["oauth_token"];
				$oauth_token_secret = $tokens["oauth_token_secret"];
				
				$yModel->addYammerData($userid, $oauth_token, $oauth_token_secret);
				
				$yammerRequestToken = $oauth_token;
			}
		}
		else 
		{
			$errMessage = "Please set userid";
		}
		$this->view->setProperty("status", $status ? 1 : 0);
		$this->view->setProperty("errMessage", $errMessage);
		$this->view->setProperty("yammerRequestToken", $yammerRequestToken);
		
		$this->view->showStatusYammer();
		
	}
}
?>